package com.king.juc.threads;

import lombok.extern.slf4j.Slf4j;

/**
 * 线程与任务分开
 * @author king
 * @date 2020/9/2 13:35
 */
@Slf4j(topic = "c.ThreadDemo")
public class RunnableDemo {
    public static void main(String[] args) {
        // 线程任务
        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                log.debug("r1 running");
            }
        };

        // lambda优化
        Runnable r2 = () -> log.debug("r2 running");

        // 创建一个线程
        Thread t1 = new Thread(r1, "t1");
        Thread t2 = new Thread(r2, "t2");

        // 启动线程
        t1.start();
        t2.start();

        log.debug("main running");
    }
}
